/* eslint-disable max-lines */
import * as BASE from '@/stores/definitions-base';
import { t } from '@lingui/macro';
import React from 'react';

const {
  DATETIME_TEXT,
  DATE_TEXT,
  TIME_TEXT,
  EMPTY_TEXT,
  ENUMS: ENUMSBase,
  FieldsGrid: FieldGridBase,
  TitleGrid,
  column: columnBase,
  toSelectDataSource,
} = BASE;
export { DATETIME_TEXT, DATE_TEXT, EMPTY_TEXT, TIME_TEXT, TitleGrid, toSelectDataSource };

export function column(...args) {
  return columnBase(orderModel, ...args);
}

export function FieldsGrid(props) {
  return <FieldGridBase model={orderModel} {...props} />;
}

//----------------------------------------------------------------------
export const ENUMS = {
  ...ENUMSBase,
  states: {
    0: t`已取消`,
    1: t`待派车`,
    2: t`进行中`,
    3: t`已完成`,
  },
  orderType: {
    0: t`点对点`,
    1: t`时租`,
  },
  // 0：包车任务，1：专线任务`
  taskType: {
    0: t`包车任务`,
    1: t`专线任务`,
  },
  language: {
    1: t`普通话`,
    2: t`粤语`,
    3: t`英语`,
  },
};

export const MAGIC_NUMBERS = {
  // 任务类型  0-已取消 1-待派车 2-进行中 3-已完成
  TASK_STATE: {
    CANCEL: '0',
    WAITING: '1',
    START: '2',
    FINISH: '3',
  },
  // 司机状态 0-取消 1-已派车 2-司机已出发 3-接到乘客/开始上客 4-行程已开始 5-行程已结束`,
  DRIVER_STATE: {
    CANCEL: '0',
    SEND_CAR: '1',
    GOING: '2',
    PICKED: '3',
    START: '4',
    FINISH: '5',
  },
};

export const orderModel = {
  orderBaseModel: {
    label: t`订单相关信息`,
    flightNumber: {
      label: t`航班号`,
    },
    orderType: {
      label: t`订单类型`,
      text: (v) => ENUMS.orderType[v],
      // 0 - 点对点；1 - 时租`,
    },
    vehicleId: {
      label: t`车辆id`,
    },
    driverId: {
      label: t`司机id`,
    },
    driverName: {
      label: t`司机名`,
    },
    language: {
      label: t`语言要求`,
      text: (_, record) => {
        const { language = [] } = record?.orderBaseModel;
        const text = language?.reduce((res, cur) => {
          res.push(ENUMS.language[cur]);
          return res;
        }, []).join('、');
        return text;
      },
    },
    passengerName: {
      label: t`乘坐人`,
    },
    passengerPhone: {
      label: t`乘坐人电话`,
    },
    subscribeName: {
      label: t`预约人`,
    },
    subscribePhone: {
      label: t`预约人电话`,
    },
    number: {
      label: t`人数`,
    },
    numberOfLuggage: {
      label: t`行李数`,
    },
    startMainArea: {
      label: t`开始城市编号`,
    },
    startMinorArea: {
      label: t`开始区域编号`,
    },
    startStationName: {
      label: t`开始站点名称`,
    },
    endMainArea: {
      label: t`结束城市编号`,
    },
    endMinorArea: {
      label: t`结束区域编号`,
    },
    endStationName: {
      label: t`结束站点名称`,
    },
    predictBeginDate: {
      label: t`预估开始时间`,
      text: DATETIME_TEXT,
    },
    predictEndDate: {
      label: t`预估结束时间`,
    },
    isPass: {
      label: t`是否过关`,
    },
    portType: {
      label: t`口岸类型，0 - 深圳湾口岸；1 - 澳门口岸；2 - 珠海口岸`,
    },
    isMap: {
      label: t`需要地图链接`,
    },
    predictTime: {
      label: t`预估时长`,
    },
    mileage: {
      label: t`里程`,
    },
    beginName: {
      label: t`开始地址`,
      ui: {
        span: 3,
      },
    },
    beginTude: {
      label: t`开始地址经纬度`,
    },
    endName: {
      label: t`结束地址`,
      ui: {
        span: 3,
      },
    },
    endTude: {
      label: t`结束地址经纬度`,
    },
    surcharges: [
      {
        label: t`附加费列表`,
      },
    ],
    roadFee: {
      label: t`路桥费`,
    },
    oilFee: {
      label: t`加油费`,
    },
    partFee: {
      label: t`停车费`,
    },
    repairFee: {
      label: t`维修费`,
    },
    otherFee: {
      label: t`其他费用`,
    },
    surchargeExplain: {
      label: t`附加费说明`,
    },
    addFee: {
      label: t`附加总费用`,
    },
    surchargePayStatus: {
      label: t`附加费支付状态，0 - 未支付；1 - 已支付；`,
    },
    surchargePayUrl: {
      label: t`附加费微信支付地址`,
    },
  },
  driverInfo: [
    {
      label: t`相关司机信息`,
      number: {
        label: t`工单编号`,
      },
      licenseNo: {
        label: t`车辆号牌`,
        mainland: {
          label: t`大陆车牌`,
          text: (v, record) => {
            const { licenseNo = '' } = record?.DRIVER || {};
            const [mainland] = licenseNo?.split('/');
            return mainland || t`无`;
          },
        },
        hk: {
          label: t`港澳车牌`,
          text: (v, record) => {
            const { licenseNo = '' } = record?.DRIVER || {};
            const [__, hk] = licenseNo?.split('/');
            return hk || t`无`;
          },
        },
      },
      vehicle: {
        label: t`承运车辆`,
      },
      driverId: {
        label: t`司机id`,
      },
      name: {
        label: t`司机姓名`,
      },
      phone: {
        label: t`司机电话`,
      },
      state: {
        label: t`司机状态`,
        //  0-取消 1-已派车 2-司机已出发 3-接到乘客/开始上客 4-行程已开始 5-行程已结束`,
      },
      remark: {
        label: t`取消备注`,
      },
    },
  ],
  number: {
    label: t`任务编号 BCRW+yyyyMMdd+0001 ZXRW+yyyyMMdd+0001`,
  },
  orderIds: [
    {
      label: t`相关订单集合`,
    },
  ],
  state: {
    label: t`状态`,
    text: (v) => ENUMS.states[v],
    // 0-已取消 1-待派车 2-进行中 3-已完成
  },
  departureTime: {
    label: t`出发时间`,
    text: DATETIME_TEXT,
  },
  taskType: {
    label: t`任务类型`,
    text: (v) => ENUMS.taskType[v],
    // 0：包车任务，1：专线任务`,
  },
  carrierCompany: {
    label: t`承运公司`,
  },
  dispatcher: {
    label: t`调度员`,
  },
  dispatcherName: {
    label: t`调度员名称`,
  },
  carrierCompanyName: {
    label: t`承运公司`,
    ui_view: {
      itemProps: {
        label: t`公司名称`,
      },
    },
  },
  carrierPrice: {
    label: t`公司费用`,
  },
  totalPrice: {
    label: t`任务总价`,
  },
  negotiatedPrice: {
    label: t`协议价格`,
  },
  remark: {
    label: t`调度员派车备注`,
    ui: {
      span: 4,
    },
  },
  dispatchRemarks: {
    label: t`未备案司机信息`,
    ui: {
      span: 4,
    },
  },
  cancelRemark: {
    label: t`取消备注`,
    ui: {
      span: 4,
    },
  },
  driverServiceFee: {
    label: t`司机费用`,
  },
  midwayFee: {
    label: t`中途费用`,
  },
  driverDisbursement: {
    label: t`司机垫付费用`,
  },
  fleetSettlement: {
    label: t`公司结算状态`,
    text: (v) => (v ? t`已结算` : t`未结算`),
  },
  driverSettlement: {
    label: t`司机结算`,
    text: (v) => (v ? t`已结算` : t`未结算`),
    ui_view: {
      itemProps: {
        label: t`司机结算状态`,
      },
    },
  },
  orderSettlement: {
    label: t`下单人后付费用是否结算`,
  },
  cancelTime: {
    label: t`取消时间`,
    text: DATETIME_TEXT,
  },
  completionTime: {
    label: t`完成时间`,
  },
  companySettlementId: {
    label: t`公司结算id`,
  },
  driverSettlementId: {
    label: t`司机结算id`,
  },
  closingOfDistribution: {
    label: t`是否分账结束`,
  },
  direction: {
    label: t`false-第一段任务 true-第二段任务`,
  },
  tickets: [
    {
      label: t`车票信息`,
      orderId: {
        label: t`订单id`,
      },
      ticketCode: {
        label: t`车票号`,
      },
      ticketPrice: {
        label: t`票价`,
      },
      shift: {
        label: t`班次id`,
      },
      fromStation: {
        label: t`上车站点`,
      },
      fromStationName: {
        label: t`上车站点名称`,
      },
      fromStationAddress: {
        label: t`上车站点地址`,
      },
      toStation: {
        label: t`下车站点`,
      },
      toStationName: {
        label: t`下车站点名称`,
      },
      toStationAddress: {
        label: t`下车站点地址`,
      },
      writeOffDate: {
        label: t`核销时间 UTC格式`,
      },
      state: {
        label: t`状态 0：未乘车，1：已乘车`,
      },
      passenger: {
        label: t`乘车人（平台用户username）`,
      },
      passengerName: {
        label: t`乘车人名称`,
      },
      passengerPhone: {
        label: t`乘车人电话`,
      },
    },
  ],
  accountRequestInfos: [
    {
      label: t`分账请求信息列表`,
      appId: {
        label: t`appId`,
      },
      id: {
        label: t`订单id`,
      },
      transactionId: {
        label: t`微信支付订单号`,
      },
      outOrderNo: {
        label: t`商户系统内部的分账单号`,
      },
      orderId: {
        label: t`微信分账单号,微信支付系统返回的唯一标识`,
      },
      state: {
        label: t`分账单状态（每个接收方的分账结果请查看receivers中的result字段）<br/> 1、PROCESSING：处理中<br/> 2、FINISHED：分账完成`,
      },
      receivers: [
        {
          label: t`分账方信息列表`,
          type: {
            label: t`分账接收方类型<br/> 1、MERCHANT_ID：商户号<br/> 2、PERSONAL_OPENID：个人openid（由父商户APPID转换得到）`,
          },
          description: {
            label: t`分账的原因描述，分账账单中需要体现`,
          },
          account: {
            label: t`分账接收方账号：<br/> 1、类型是MERCHANT_ID时，是商户号（mch_id或者sub_mch_id）<br/> 2、类型是PERSONAL_OPENID时，是个人openid`,
          },
          username: {
            label: t`合伙人 / 公司 / 司机`,
          },
          name: {
            label: t`合伙人名 / 公司名 / 司机`,
          },
          userType: {
            label: t`身份 1-合伙人 2-公司 3-司机`,
          },
          amount: {
            label: t`分账金额 单位为分，只能为整数，不能超过原订单支付金额及最大分账比例金额`,
          },
          result: {
            label: t`分账结果<br/> 1、PENDING：待分账<br/> 2、SUCCESS：分账成功<br/> 3、CLOSED：已关闭`,
          },
          failReason: {
            label: t`分账失败原因，当分账结果result为CLOSED（已关闭）时，返回该字段<br/> 1、ACCOUNT_ABNORMAL：分账接收账户异常<br/> 2、NO_RELATION：分账关系已解除<br/> 3、RECEIVER_HIGH_RISK：高风险接收方<br/> 4、RECEIVER_REAL_NAME_NOT_VERIFIED：接收方未实名<br/> 5、NO_AUTH：分账权限已解除<br/> 6、RECEIVER_RECEIPT_LIMIT：接收方已达收款限额<br/> 7、PAYER_ACCOUNT_ABNORMAL：分出方账户异常`,
          },
          detailId: {
            label: t`微信分账明细单号`,
          },
          inflowPlatform: {
            label: t`这笔资金是否放回平台`,
          },
          redistribute: {
            label: t`重新分账信息`,
            outOrderNo: {
              label: t`商户系统内部的分账单号`,
            },
            orderId: {
              label: t`微信分账单号,微信支付系统返回的唯一标识`,
            },
            state: {
              label: t`分账单状态（每个接收方的分账结果请查看receivers中的result字段）<br/> 1、PROCESSING：处理中<br/> 2、FINISHED：分账完成`,
            },
            result: {
              label: t`分账结果<br/> 1、PENDING：待分账<br/> 2、SUCCESS：分账成功<br/> 3、CLOSED：已关闭`,
            },
            failReason: {
              label: t`分账失败原因，当分账结果result为CLOSED（已关闭）时，返回该字段`,
            },
            detailId: {
              label: t`微信分账明细单号`,
            },
          },
        },
      ],
    },
  ],
  crBy: {
    label: t`创建者`,
  },
  upBy: {
    label: t`最后修改者`,
  },
  crDate: {
    label: t`创建时间`,
    text: DATETIME_TEXT,
  },
  upDate: {
    label: t`最后修收时间`,
  },
  tenantId: {
    label: t`租户ID`,
  },
  id: {
    label: t`任务编号`,
  },
  // 前端新增字段
  startArea: {
    label: t`上车区域`,
    text: (_, record) => {
      const { startMainAreaText, startMinorAreaText } = record?.orderBaseModel || {};
      const text = `${startMainAreaText}-${startMinorAreaText}`;
      return text;
    },
  },
  endArea: {
    label: t`下车区域`,
    text: (_, record) => {
      const { endMainAreaText, endMinorAreaText } = record?.orderBaseModel || {};
      const text = `${endMainAreaText}-${endMinorAreaText}`;
      return text;
    },
  },
  showPrice: {
    label: t`价格(公司/司机)`,
    text: (_, record) => {
      const { carrierPrice, driverServiceFee } = record;
      return t`${carrierPrice},${driverServiceFee}`;
    },
  },
  showOrderIds: {
    label: t`相关订单`,
    text: (_, record) => {
      const { orderIds } = record;
      const dom = orderIds.map((id, idx) => (
        <>
          <span key={`${id}-${idx}`}>{id}</span>
          <br />
        </>
      ));
      return dom;
    },
  },
  taskLogs: {
    beginTime: {
      label: t`开始时间`,
      text: (v, record) => {
        const { beginTime } = record?.TASKLOG || {};
        return DATETIME_TEXT(beginTime);
      },
    },
    completeTime: {
      label: t`结束时间`,
      text: (v, record) => {
        const { completeTime } = record?.TASKLOG || {};
        return DATETIME_TEXT(completeTime);
      },
    },
    destinationTime: {},
    receiveTime: {},
  },
};
